package utils

import (
	"golang.org/x/crypto/bcrypt"
)

// 对密码进行加密
func Encoder(password string) (string, error) {
	hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
	if err != nil {
		return "", err
	}
	return string(hash), nil
}

func Decoder(loginpass string, pass string) (bool, error) {
	err := bcrypt.CompareHashAndPassword([]byte(pass), []byte(loginpass))
	if err != nil {
		return false, err
	}
	return true, nil
}
